package cn.edu.scau.cmi.ema.domain;


import javax.persistence.*;
import javax.xml.bind.annotation.*;
import java.io.Serializable;

@Entity
@NamedQueries({ @NamedQuery(name = "findAllSpiders", query = "select mySpider from Spider mySpider"),
		@NamedQuery(name = "findSpiderByName", query = "select mySpider from Spider mySpider where mySpider.name = ?1"),
		@NamedQuery(name = "findSpiderByNameContaining", query = "select mySpider from Spider mySpider where mySpider.name like concat('%',?1,'%')"),
		@NamedQuery(name = "findSpiderByTitle", query = "select mySpider from Spider mySpider where mySpider.title = ?1"),
		@NamedQuery(name = "findSpiderByTitleContaining", query = "select mySpider from Spider mySpider where mySpider.title like concat('%',?1,'%')"),
		@NamedQuery(name = "findSpiderByHref", query = "select mySpider from Spider mySpider where mySpider.href = ?1"),
		@NamedQuery(name = "findSpiderByHrefContaining", query = "select mySpider from Spider mySpider where mySpider.href like concat('%',?1,'%')"),
		@NamedQuery(name = "findSpiderByTime", query = "select mySpider from Spider mySpider where mySpider.time = ?1"),
		@NamedQuery(name = "findSpiderByTimeContaining", query = "select mySpider from Spider mySpider where mySpider.time like concat('%',?1,'%')"),
		@NamedQuery(name = "findSpiderByAuthor", query = "select mySpider from Spider mySpider where mySpider.author = ?1"),
		@NamedQuery(name = "findSpiderByAuthorContaining", query = "select mySpider from Spider mySpider where mySpider.author like concat('%',?1,'%')"),
		@NamedQuery(name = "findSpiderBySource", query = "select mySpider from Spider mySpider where mySpider.source = ?1"),
		@NamedQuery(name = "findSpiderBySourceContaining", query = "select mySpider from Spider mySpider where mySpider.source like concat('%',?1,'%')"),
		@NamedQuery(name = "findSpiderByMainContent", query = "select mySpider from Spider mySpider where mySpider.mainContent = ?1"),
		@NamedQuery(name = "findSpiderByMainContentContaining", query = "select mySpider from Spider mySpider where mySpider.mainContent like concat('%',?1,'%')"),
		@NamedQuery(name = "findSpiderByTokenization", query = "select mySpider from Spider mySpider where mySpider.tokenization = ?1"),
		@NamedQuery(name = "findSpiderByTokenizationContaining", query = "select mySpider from Spider mySpider where mySpider.tokenization like concat('%',?1,'%')"),
		@NamedQuery(name = "findSpiderByIs_ema", query = "select mySpider from Spider mySpider where mySpider.is_ema = ?1"),
		@NamedQuery(name = "findSpiderByIs_check", query = "select mySpider from Spider mySpider where mySpider.is_check = ?1"),
		@NamedQuery(name = "findSpiderByExport", query = "select mySpider from Spider mySpider where mySpider.export = ?1"),
		@NamedQuery(name = "findSpiderByDescription", query = "select mySpider from Spider mySpider where mySpider.description = ?1"),
		@NamedQuery(name = "findSpiderByDescriptionContaining", query = "select mySpider from Spider mySpider where mySpider.description like concat('%',?1,'%')"),
		@NamedQuery(name = "findSpiderById", query = "select mySpider from Spider mySpider where mySpider.id = ?1"),
		@NamedQuery(name = "findSpiderByPrimaryKey", query = "select mySpider from Spider mySpider where mySpider.id = ?1 "),
		@NamedQuery(name = "deleteSpidersByIds", query = "delete Spider where id in (?1)"),
		@NamedQuery(name = "findSpidersByIds", query = "select mySpider from Spider mySpider where mySpider.id in (?1)"),
		@NamedQuery(name = "findSpiderByPhyscialPrimaryKey", query = "select mySpider from Spider mySpider where  mySpider.name = ?1"),
		@NamedQuery(name = "countSpidersByName", query = "select count(mySpider)  from Spider mySpider where mySpider.name like concat('%',?1,'%')") })
@Table(catalog = "ema", name = "spider")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "ema/cn/edu/scau/cmi/ema/domain", name = "Spider")
@XmlRootElement(namespace = "ema/cn/edu/scau/cmi/ema/domain")

public class Spider implements Serializable, Comparable<Spider> {

	private static final long serialVersionUID = 1L;

	@Column(name = "id", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@XmlElement
	Integer id;

	@Column(name = "name")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String name;

	@Column(name = "title")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String title;

	@Column(name = "href")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String href;

	@Column(name = "time")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String time;

	@Column(name = "author")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String author;

	@Column(name = "source")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String source;

	@Column(name = "mainContent")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String mainContent;

	@Column(name = "tokenization")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String tokenization;

	@Column(name = "is_ema")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Boolean is_ema;

	@Column(name = "is_check")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Boolean is_check;

	@Column(name = "export")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Boolean export;

	@Column(name = "description")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String description;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return this.id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return this.name;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getTitle() {
		return this.title;
	}

	public void setHref(String href) {
		this.href = href;
	}

	public String getHref() {
		return this.href;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getTime() {
		return this.time;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getAuthor() {
		return this.author;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public String getSource() {
		return this.source;
	}

	public void setMainContent(String mainContent) {
		this.mainContent = mainContent;
	}

	public String getMainContent() {
		return this.mainContent;
	}

	public void setTokenization(String tokenization) {
		this.tokenization = tokenization;
	}

	public String getTokenization() {
		return this.tokenization;
	}

	public void setIs_ema(Boolean is_ema) {
		this.is_ema = is_ema;
	}

	public Boolean getIs_ema() {
		return this.is_ema;
	}

	public void setIs_check(Boolean is_check) {
		this.is_check = is_check;
	}

	public Boolean getIs_check() {
		return this.is_check;
	}

	public void setExport(Boolean export) {
		this.export = export;
	}

	public Boolean getExport() {
		return this.export;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return this.description;
	}

	public void copy(Spider that) {

		setId(that.getId());

		setName(that.getName());
		setTitle(that.getTitle());
		setHref(that.getHref());
		setTime(that.getTime());
		setAuthor(that.getAuthor());
		setSource(that.getSource());
		setMainContent(that.getMainContent());
		setTokenization(that.getTokenization());
		setIs_ema(that.getIs_ema());
		setIs_check(that.getIs_check());
		setExport(that.getExport());
		setDescription(that.getDescription());

	}

	public Spider() {

	}

	@Override
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");

		buffer.append("name=[").append(name).append("] ");
		buffer.append("title=[").append(title).append("] ");
		buffer.append("href=[").append(href).append("] ");
		buffer.append("time=[").append(time).append("] ");
		buffer.append("author=[").append(author).append("] ");
		buffer.append("source=[").append(source).append("] ");
		buffer.append("mainContent=[").append(mainContent).append("] ");
		buffer.append("tokenization=[").append(tokenization).append("] ");
		buffer.append("is_ema=[").append(is_ema).append("] ");
		buffer.append("is_check=[").append(is_check).append("] ");
		buffer.append("export=[").append(export).append("] ");
		buffer.append("description=[").append(description).append("] ");

		return buffer.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Spider))
			return false;
		Spider comparedSpider = (Spider) obj;
		if (!CheckPropertyEqual(this.name, comparedSpider.name)) {
			return false;
		}
		return true;
	}

	public static <T> boolean CheckPropertyEqual(T originProperty, T comparedProperty) {
		// 基本类型经过参数传递后会自动装箱
		String[] className = originProperty.getClass().getName().split("\\.");
		if (className[0].equals("java") && className[1].equals("math")) {
			return ((Comparable) originProperty).compareTo(comparedProperty) == 0 ? true : false;
		} else {
			return originProperty.equals(comparedProperty);
		}
	}

	@Override
	public int compareTo(Spider o) {
		if (this.getId() > o.getId()) {
			return 1;
		} else if (this.getId() == o.getId()) {
			return 0;
		} else {
			return -1;
		}

	}
}
